﻿using System;

using NUnit.Framework;

using octalforty.Syndication.Core;
using octalforty.Syndication.Core.Rss;
using octalforty.Syndication.Core.Rss.Aggregators;

namespace octalforty.Syndication.UnitTests.Core.Rss.Aggregators
{
    /// <summary>
    /// <see cref="RssChannelAggregator"/> unit tests.
    /// </summary>
    [TestFixture()]
    public class RssChannelAggregatorTestFixture : RssAggregatorTestFixtureBase
    {
        [Test()]
        public void Aggregate()
        {
            IAggregator aggregator = new RssChannelAggregator();
            ISyndicationFeed syndicationFeed = new RssFeed();

            aggregator.Aggregate(feedDocument, ref syndicationFeed);

            Assert.AreEqual("Liftoff News", syndicationFeed.Title);
            Assert.AreEqual("http://liftoff.msfc.nasa.gov/", syndicationFeed.Link);
            Assert.AreEqual("Liftoff to Space Exploration.", syndicationFeed.Description);

            RssFeed rssFeed = syndicationFeed as RssFeed;

            Assert.IsNotNull(rssFeed);
            Assert.AreEqual("en-us", rssFeed.Channel.Language);
            Assert.AreEqual(new DateTime(2003, 6, 10, 4, 0, 0), rssFeed.Channel.PublishedOn.Value);
            Assert.AreEqual(new DateTime(2003, 6, 10, 9, 41, 1), rssFeed.Channel.UpdatedOn.Value);
            Assert.AreEqual("Weblog Editor 2.0", rssFeed.Channel.Generator);
            Assert.AreEqual("editor@example.com", rssFeed.Channel.ManagingEditor.EmailAddress);
            Assert.AreEqual("webmaster@example.com", rssFeed.Channel.WebMaster.EmailAddress);
        }

        #region RssAggregatorTestFixtureBase Members
        /// <summary>
        /// When overriden in a derived class, creates an instance of <see cref="IAggregator"/>.
        /// </summary>
        /// <returns></returns>
        protected override IAggregator CreateInstance()
        {
            return new RssChannelAggregator();
        }
        #endregion
    }
}
